package com.example.cofeed.adapter;

import android.support.annotation.Nullable;
import android.widget.ImageView;

import com.blankj.utilcode.util.ObjectUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.cofeed.R;
import com.example.cofeed.entity.MessageNotification;

import java.util.List;

public class ReplyCommentsAdapter extends BaseQuickAdapter<MessageNotification, BaseViewHolder> {
    private int mType;

    public ReplyCommentsAdapter() {
        super(R.layout.adapter_reply_comments);
    }

    @Override
    protected void convert(BaseViewHolder helper, MessageNotification item) {

        RequestOptions options = new RequestOptions()
                .error(R.mipmap.userimg)
                .placeholder(R.mipmap.userimg);

        helper.setText(R.id.tv_title, item.title);
        helper.setText(R.id.tv_date, item.addtime);

        switch (mType){
            //咨询消息
            case 0:
                Glide.with(mContext).load(item.icon).apply(options).into((ImageView) helper.itemView.findViewById(R.id.iv_image));
                helper.setText(R.id.tv_content, item.content);

                helper.setText(R.id.tv_name, item.name);
                if (ObjectUtils.isNotEmpty(item.answer)) {
                    helper.setText(R.id.tv_reply, "回复：" + item.answer);
                    helper.setGone(R.id.tv_reply, true);
                }else {
                    helper.setGone(R.id.tv_reply, false);
                }

                helper.setVisible(R.id.tv_reply, true);
                helper.setVisible(R.id.tv_reply_click, false);

                break;
            //评论回复
            case 1:
                Glide.with(mContext).load(item.picture).apply(options).into((ImageView) helper.itemView.findViewById(R.id.iv_image));
                helper.setText(R.id.tv_content, item.content);

                helper.setText(R.id.tv_name, item.username);
                if (ObjectUtils.isNotEmpty(item.reply)){
                    helper.setText(R.id.tv_reply, "回复：" + item.reply);
                    helper.setGone(R.id.tv_reply, true);
                }else {
                    helper.setGone(R.id.tv_reply, false);
                }
                break;
                //商机消息
            case 2:
                Glide.with(mContext).load(item.picture).apply(options).into((ImageView) helper.itemView.findViewById(R.id.iv_image));
                helper.setText(R.id.tv_content, item.question);

                helper.setText(R.id.tv_name, item.name);
                if (ObjectUtils.isEmpty(item.answer)){
                    helper.setVisible(R.id.tv_reply, false);
                    helper.setVisible(R.id.tv_reply_click, true);
                    helper.addOnClickListener(R.id.tv_reply_click);
                }else {
                    helper.setText(R.id.tv_reply, "回复：" + item.answer);
                    helper.setVisible(R.id.tv_reply, true);
                    helper.setVisible(R.id.tv_reply_click, false);
                }


                break;
        }


    }

    public void setType(int type){
        this.mType = type;
    }


}
